﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.IO;
using System.ComponentModel;

namespace Httlgd.DataCenter.Services.Sms.ServiceLibrary
{
    [MessageContract]
    public abstract class RemoteFileInfo : IDisposable
    {
        /// <summary>
        /// Represent ID of the associated record 
        /// (SermonID if DocumentType is SermonAudio, AttachmentID if DocumentType is Attachment)
        /// </summary>
        [MessageHeader(MustUnderstand = true)]
        [DefaultValue((int)0)]
        public int RelatedRecordID { get; set; }

        [MessageHeader(MustUnderstand = true)]
        public string FileName  { get; set; }

        [MessageHeader(MustUnderstand = true)]
        [DefaultValue((long)0)]
        public long Length { get; set; }

        [MessageBodyMember(Order = 1)]
        public Stream FileByteStream { get; set; }

        #region Implement IDisposable
        public void Dispose()
        {
            if (FileByteStream != null)
            {
                FileByteStream.Close();
                FileByteStream = null;
            }
        }
        #endregion
    }

    [MessageContract]
    public class UploadFileRequest : RemoteFileInfo
    {
        [MessageHeader(MustUnderstand = true)]
        [DefaultValue(DocumentType.SermonAudio)]
        public DocumentType DocumentType { get; set; }
    }

    [MessageContract]
    public class DownloadFileResponse : RemoteFileInfo
    {
        [MessageHeader(MustUnderstand=true)]
        public string Error { get; set; }
    }
}
